package service

import (
	"context"
	"insighttracking/query/dao"
	"insighttracking/query/model"
)

type _sendGoodsRecordDetailService struct{}

func (s _sendGoodsRecordDetailService) CreateBatchApi(ctx context.Context, tx *dao.QueryTx, data []*model.SendGoodsRecordDetailEntity) error {
	if err := tx.SendGoodsRecordDetailEntity.WithContext(ctx).CreateInBatches(data, len(data)); err != nil {
		return err
	}
	return nil
}

func (s _sendGoodsRecordDetailService) GetSendGoodsRecordDetailApi(ctx context.Context, id int64) ([]*model.SendGoodsRecordDetailEntity, error) {
	return dao.SendGoodsRecordDetailEntity.WithContext(ctx).Where(dao.SendGoodsRecordDetailEntity.SendGoodsRecordID.Eq(id)).Find()
}

func (s _sendGoodsRecordDetailService) GetSendGoodsRecordDetailBySpuIdApi(ctx context.Context, id, spuId int64) (*model.SendGoodsRecordDetailEntity, error) {
	return dao.SendGoodsRecordDetailEntity.WithContext(ctx).Where(
		dao.SendGoodsRecordDetailEntity.SendGoodsRecordID.Eq(id),
		dao.SendGoodsRecordDetailEntity.SpuID.Eq(spuId),
	).First()
}

func (s _sendGoodsRecordDetailService) CreateApi(ctx context.Context, tx *dao.QueryTx, data *model.SendGoodsRecordDetailEntity) error {
	if err := tx.SendGoodsRecordDetailEntity.WithContext(ctx).Create(data); err != nil {
		return err
	}
	return nil
}

var SendGoodsRecordDetailService = new(_sendGoodsRecordDetailService)
